package stubs
{
	import mx.core.EmbeddedFontRegistry;
	import mx.events.FlexEvent;
	
	import spark.components.Application;
	import spark.components.Button;
	import spark.core.SpriteVisualElement; EmbeddedFontRegistry;
	// Need this for some other stuff... something in UIComponent
	// sigh...
	import mx.managers.BrowserManagerImpl; BrowserManagerImpl;
	// A friend of the guy above...
	import mx.managers.HistoryManagerImpl; HistoryManagerImpl;
	// Yet another masterpiece...
	import mx.managers.PopUpManagerImpl; PopUpManagerImpl;
	// Another piece of art that hopefully gets deleted some time...
	import mx.managers.DragManagerImpl; DragManagerImpl;
	// Moar abominations...
	import mx.core.TextFieldFactory;TextFieldFactory;
	// even moar...
	import mx.styles.StyleManagerImpl; StyleManagerImpl;
	
	// Not sure if this is needed, this was a bizarre finding...
	import mx.managers.systemClasses.ChildManager;
	import mx.core.UIComponentGlobals;
	import mx.managers.LayoutManager;
	import mx.core.FlexGlobals;
	import mx.styles.IStyleManager2;
	import mx.managers.SystemManager;

 ChildManager;

	
	[SWF(width="800", height="600", scriptTimeLimit="15", 
		frameRate="30", backgroundColor="0x3E2F1B")]
	[Frame(factoryClass="stubs.SparkSystemManagerStub")]
	[Frame(extraFrame="stubs.SparkSystemManagerStub")]
	[Mixin]
	
	public class SparkApplicationStub extends Application
	{
		public namespace mx_internal = 
			"http://www.adobe.com/2006/flex/mx/internal";
		
		use namespace mx_internal;
		// Another masterpiece...
		UIComponentGlobals.layoutManager = LayoutManager.getInstance();
		UIComponentGlobals.layoutManager.usePhasedInstantiation = true;
		
		public function SparkApplicationStub()
		{
			super();
			FlexGlobals.topLevelApplication = this;
			super.addEventListener(
				FlexEvent.APPLICATION_COMPLETE, 
				this.applicationCompleteHandler);
		}
		
		public static function init(fbs:SystemManager):void
		{
			// This piece of poop comes from FlexInit
			var styleManager:IStyleManager2 = fbs.getImplementation("mx.styles::IStyleManager2") as IStyleManager2;
			var styleNames:Array = ["lineHeight", "unfocusedTextSelectionColor", "kerning", "showErrorSkin", "digitCase", "inactiveTextSelectionColor", "listAutoPadding", "showErrorTip", "justificationRule", "textDecoration", "dominantBaseline", "fontThickness", "textShadowColor", "trackingRight", "blockProgression", "leadingModel", "listStylePosition", "textAlignLast", "textShadowAlpha", "textAlpha", "letterSpacing", "chromeColor", "rollOverColor", "fontSize", "baselineShift", "focusedTextSelectionColor", "paragraphEndIndent", "fontWeight", "breakOpportunity", "leading", "symbolColor", "renderingMode", "fontSharpness", "paragraphStartIndent", "layoutDirection", "justificationStyle", "wordSpacing", "listStyleType", "contentBackgroundColor", "paragraphSpaceAfter", "contentBackgroundAlpha", "fontAntiAliasType", "textRotation", "errorColor", "cffHinting", "direction", "locale", "backgroundDisabledColor", "digitWidth", "touchDelay", "ligatureLevel", "textIndent", "firstBaselineOffset", "themeColor", "clearFloats", "fontLookup", "tabStops", "paragraphSpaceBefore", "textAlign", "fontFamily", "interactionMode", "lineThrough", "whiteSpaceCollapse", "fontGridFitType", "alignmentBaseline", "trackingLeft", "fontStyle", "dropShadowColor", "accentColor", "disabledColor", "downColor", "focusColor", "textJustify", "color", "alternatingItemColors", "typographicCase"];
			
			for (var i:int = 0; i < styleNames.length; i++)
			{
				styleManager.registerInheritingStyle(styleNames[i]);
			}
			// This piece of poop is usually added to Application-generated class. 
			styleManager.initProtoChainRoots();
			trace(styleManager.getStyleDeclaration("global"));
			styleManager.getStyleDeclaration("spark.components.supportClasses.TextBase");
			styleManager.getStyleDeclaration("spark.components.supportClasses.SkinnableComponent");
			styleManager.getStyleDeclaration("spark.components.Button.emphasized");
			trace(styleManager.getStyleDeclaration("spark.components.Button"));
			trace("constructed");
		}
		
		protected function applicationCompleteHandler(event:FlexEvent):void
		{
			super.removeEventListener(
				FlexEvent.APPLICATION_COMPLETE, 
				this.applicationCompleteHandler);
			var button:Button = new Button();
			button.label = "Test";
			super.addElement(button);
			trace("applicationComplete");
		}
	}
}